<template>
	<view class="details_second">
		<view class="banner">
			<u-swiper :list="list" height='750' border-radius='0' mode='number' indicator-pos='bottomRight'></u-swiper>
		</view>
		<!--  -->
		<view class="info">
			<view class="title">{{goods_name}}</view>
			<view class="money">
				<!-- <image src="@/static/images/details_icon1.jpg" mode=""></image> -->
				<text>￥{{price}}</text>
			</view>
			<view class="text">
				<text>单位：{{unit}}</text>
				<text>库存：{{inventory}}</text>
			</view>
		</view>
		<!--  -->
		<view class="shop_info" v-if="type==1 && shop">
			<image :src="shop.image" mode="aspectFill"></image>
			<view class="text">
				<view class="name">{{shop.shop_name}}</view>
				<view class="txt">总店提货券额：{{shop.balance}}</view>
			</view>
		</view>
		<!--  -->
		<view class="content">
			<view class="text" v-html="details_content"></view>
		</view>
		<!-- 底部 -->
		<view :style="[paddingStyle]"></view>
		<view class="footer_btn" :style="[botStyle]">
			<view class="left" @click="phoneBtn" v-if="type==1 && userinfo.is_mobile==1">联系店长</view>
			<view class="left" @click="phoneBtn" v-if="type!==1">联系客服</view>
			<view class="btn" @click="show=true">立即购买</view>
		</view>
		<!-- 弹框 -->
		<u-popup v-model="show" mode="bottom" border-radius="20" :safe-area-inset-bottom='false' :closeable='true'>
			<view class="box_main">
				<view class="goods">
					<view class="image">
						<u-image width="100%" height="100%" :src="list[0]"></u-image>
					</view>
					<view class="goods_info">
						<view class="name txt-cut">{{goods_name}}</view>
						<view class="money">
							<!-- <image src="@/static/images/details_icon1.jpg" mode=""></image> -->
							<text>￥{{price}}</text>
						</view>
						<view class="text">
							<text>单位：{{unit}}</text>
							<text>库存：{{inventory}}</text>
						</view>
					</view>
				</view>
				<view class="num">
					<view class="num_left">数量</view>
					<view class="num_right">
						<u-number-box :min="1" :max='inventory' :disabled-input='true' v-model="value"></u-number-box>
					</view>
				</view>
				<view class="all_price">
					<view class="num_left">总价</view>
					<view class="money">
						<!-- <image src="@/static/images/details_icon1.jpg" mode=""></image> -->
						<text>￥{{allPrice}}</text>
					</view>
				</view>
				<!--  -->
				<view class="btn" @click="submitBtn">确定</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				id:'',
				type:'',//1=仓储 2=零售 3=提货
				bottomHeight:0,
				// 
				list:[],//轮播图
				goods_name:'',//名称
				price:'',//价格
				unit:'',//单位
				inventory:'',//库存
				shop:'',//店铺信息
				details_content:'',//详情
				// 
				show:false,
				value:1,
			};
		},
		computed:{
			...mapState({
				userinfo: state => state.userinfo
			}),
			paddingStyle(){
				var height = this.bottomHeight?(this.bottomHeight*2+108+'rpx'):'128rpx'
				return {
					paddingBottom:height
				}
			},
			botStyle(){
				return {
					paddingBottom:this.bottomHeight?this.bottomHeight+'px':'20rpx'
				}
			},
			allPrice(){
				var money = (this.price*100*this.value/100).toFixed(2)
				return money
			},
		},
		onLoad(options) {
			this.type=options.type
			this.id=options.id
			uni.getSystemInfo({
				success: (res) => {
					this.bottomHeight = res.safeAreaInsets.bottom
				}
			});
			this.goodsInfo()
		},
		methods:{
			// 获取商品信息
			goodsInfo(){
				var that = this
				that.$tips.showLoading('加载中')
				var params = {
					ids:that.id
				}
				that.$httpApi.goodsDetails(params).then((res)=>{
					that.$tips.hideLoading()
					if(res.code==1){
						that.list=res.data.smallimages_text
						that.goods_name=res.data.goods_name
						that.price=res.data.price
						that.unit=res.data.unit
						that.inventory=res.data.inventory
						that.details_content=res.data.details_content
						if(that.type==1){
							that.shop=res.data.shop
						}
					}
				})
			},
			// 联系店长/客服
			phoneBtn(){
				if(this.type==1){
					uni.makePhoneCall({
						phoneNumber: this.shop.mobile
					});
				}else{
					uni.navigateTo({
						url:'/pages/other/text?type=4'
					})
				}
			},
			// 立即购买
			submitBtn(){
				var obj = {
					id:this.id,
					img:this.list[0],
					name:this.goods_name,
					price:this.price,
					num:this.value,
					allPrice:this.allPrice
				}
				this.show=false
				uni.navigateTo({
					url:'/pages/mall/order_second?type='+this.type+'&info=' + JSON.stringify(obj)
				})
			},
		}
	}
</script>

<style lang="less">
	.details_second{
		width: 100%;
		.banner{
			width: 100%;
			height: 750rpx;
		}
		.info{
			width: 100%;
			padding: 30rpx 32rpx;
			background: #fff;
			.title{
				width: 100%;
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #222222;
				line-height: 48rpx;
			}
			.money{
				width: 100%;
				padding-top: 24rpx;
				display: flex;
				align-items: center;
				image{
					display: block;
					width: 40rpx;
					height: 40rpx;
				}
				text{
					padding-left: 5rpx;
					font-size: 40rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #FF6230;
				}
			}
			.text{
				width: 100%;
				padding-top: 24rpx;
				display: flex;
				align-items: center;
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;
				text{
					padding-right: 60rpx;
				}
			}
		}
		.shop_info{
			margin-top: 24rpx;
			width: 100%;
			padding: 28rpx 32rpx;
			background: #fff;
			display: flex;
			image{
				display: block;
				width: 88rpx;
				height: 88rpx;
				border-radius: 50%;
			}
			.text{
				width: calc(100% - 88rpx);
				height: 88rpx;
				padding-left: 24rpx;
				display: flex;
				justify-content: space-between;
				flex-direction: column;
				.name{
					font-size: 32rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}
				.txt{
					font-size: 24rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}
		}
		.content{
			margin-top: 24rpx;
			margin-bottom: 24rpx;
			width: 100%;
			background: #fff;
			.text{
				width: 100%;
				::v-deep p{
					width: 100%;
					image{
						display: block;
						width: 100% !important;
					}
					img{
						display: block;
						width: 100% !important;
					}
				}
			}
		}
		.footer_btn{
			position: fixed;
			bottom: 0;
			z-index: 100;
			width: 100%;
			background: #fff;
			padding-top: 20rpx;
			padding-left: 32rpx;
			padding-right: 32rpx;
			display: flex;
			justify-content: space-between;
			.left{
				width: 332rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #666;
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				background: #F7F8FA;
				border-radius: 44rpx;
			}
			.btn{
				width: 332rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #fff;
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				background: #26C281;
				border-radius: 44rpx;
			}
			.btn_t{
				width: 100%;
			}
		}
		// 
		.box_main{
			width: 100%;
			padding: 100rpx 40rpx 0;
			.goods{
				display: flex;
				.image{
					width: 220rpx;
					height: 220rpx;
					border-radius: 10rpx;
					overflow: hidden;
				}
				.goods_info{
					padding-left: 20rpx;
					width: calc(100% - 220rpx);
					height: 220rpx;
					display: flex;
					justify-content: space-between;
					flex-direction: column;
					.name{
						width: 100%;
						font-size: 32rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
						line-height: 48rpx;
					}
					.money{
						width: 100%;
						display: flex;
						align-items: center;
						image{
							display: block;
							width: 40rpx;
							height: 40rpx;
						}
						text{
							padding-left: 5rpx;
							font-size: 40rpx;
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #FF6230;
						}
					}
					.text{
						width: 100%;
						display: flex;
						align-items: center;
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						text{
							padding-right: 60rpx;
						}
					}
				}
			}
			.num{
				width: 100%;
				padding: 50rpx 0;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.num_left{
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #2B2D30;
				}
			}
			.all_price{
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.num_left{
					font-size: 26rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #2B2D30;
				}
				.money{
					display: flex;
					align-items: center;
					image{
						display: block;
						width: 40rpx;
						height: 40rpx;
					}
					text{
						padding-left: 5rpx;
						font-size: 40rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #222;
					}
				}
			}
			.btn{
				margin: 100rpx 0 50rpx;
				width: 100%;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #fff;
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				background: #26C281;
				border-radius: 44rpx;
			}
			
		}
	}
</style>
